import { Component, OnInit, Input, OnDestroy, } from '@angular/core';
import { CoreMessageService } from '../../../core/services/core-message.service';

@Component({
  selector: 'app-detail-modal',
  templateUrl: './detail-modal.component.html',
  styleUrls: ['./detail-modal.component.scss']
})
export class DetailModalComponent implements OnInit, OnDestroy {
  // @Input() detailMsg = null;
  detailMsg = null;
  isVisible = false;
  keys = [];
  constructor(private coreMessageService: CoreMessageService) { }

  ngOnInit() {
    this.coreMessageService.showmodal.subscribe((res) => {
      this.isVisible = true;
      // 获取到数据后提取key值！
      for (let [key, value] of Object.entries(res)) {
        this.keys.push(key);
      }
      this.detailMsg = res; // 转换成json对象
    });
  }

  // 实际发挥作用的是这个
  handleCancel(): void {
    this.detailMsg = null;
    this.isVisible = false;
    this.keys = [];
  }

  ngOnDestroy() {
    this.detailMsg = null;
    this.isVisible = false;
    this.keys = [];
  }
}
